class Solution(object):
    def minimumTime(self, s):
        n = len(s)
        left_ans = [0] * n
        right_ans = [0] * n
        now_count = 0
        for i in range(n):
            if s[i] == '1':
                if now_count > 0:
                    left_ans[i] = left_ans[i - 1] + 2
                    now_count -= 1
                else:
                    now_count = 0
                    left_ans[i] = i + 1
            else:
                now_count += 1
                if i == 0:
                    left_ans[i] = 0
                else:
                    left_ans[i] = left_ans[i - 1]
        s = s[::-1]
        now_count = 0
        for i in range(n):
            if s[i] == '1':
                if now_count > 0:
                    right_ans[i] = right_ans[i - 1] + 2
                    now_count -= 1
                else:
                    now_count = 0
                    right_ans[i] = i + 1
            else:
                now_count += 1
                if i == 0:
                    right_ans[i] = 0
                else:
                    right_ans[i] = right_ans[i - 1]
        out = left_ans[-1]
        right_ans.reverse()
        for i in range(n - 1):
            out = min(out, left_ans[i] + right_ans[i + 1])
        return out

data = Solution()
s = "1100101"
print(data.minimumTime(s))
